home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: agent439@aol.com (Agent439)
- Newsgroups: comp.lang.c
- Subject: Multiplication Problem - How to multiply really big numbers, and printing the answers out.
- Date: 31 Jan 1996 19:07:18 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4ep07m$4fn@newsbf02.news.aol.com>
- Reply-To: agent439@aol.com (Agent439)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- I'm trying to write a C Program that will accept a positive integer that
- can be 100 digits long at a maximum. So far, my first example (INPUT
- 3125, 25) works except that when it tries to print out the answer, the
- number is wrong. Now I know there are 2 warnings in it, but I watched
- variables step-by-step, and it seems to get the right answer. Please
- disregard the timer part, and any disagreements what I call my variables.
- Just tell me what types should my variables be or what printf conversion
- should be in for the answer? Any suggestions to get rid of the warnings
- would be appreciated too. :-0
-
- Here is the program
- #include <math.h>
- #include <stdio.h>
- #include <time.h>
-
- #define FALSE 0
- #define TRUE !FALSE
-
- float timer(int reset);
- void main(){
-
- char a[100],b[100];
- int i, j;
- int x, y, z;
- int size,truesize;
- unsigned long pa,pb, c;
-
- a==NULL;
- b==NULL;
- printf("Enter the Multiplicand:");
- gets(a);
- while(a<0){
- printf("Positive Integers only please!");
- printf("Enter the Multiplicand:");
- gets(a);
- }
-
- printf("Enter the Multiplier:");
- gets(b);
- while(b<0){
- printf("Positive Integers only please!");
- printf("Enter the Multiplier:");
- gets(b);
- }
- size=0;
- pa=0;
- while(a[size] != 0){
- size++;
- }
- size--;
- truesize=size;
- for(size==size;size>=0;size--){
- pa += (a[size]-48)*(pow(10,(truesize-size))); //change char to integer
- value
- }
- size=0;
- pb=0;
- while(b[size] != 0){
- size++;
- }
- size--;
- truesize=size;
- for(size==size;size>=0;size--){
- pb += (b[size]-48)*(pow(10,(truesize-size))); //change char to
- integer value
- }
- //timer(TRUE);
- c=0;
- c+=(pa);//Start C with the amount in pa
- c*=(pb); //Multiply pa by the integer value of pb
- printf("The product is =======> %i \n",c);
- for(i=0;i<1000;i++){
- for(j=0;j<1000;j++){
- z= x++ + ++y;
- }
- }
- printf("Elapsed time = %.2f seconds\n", timer(FALSE));
-
- timer(TRUE);
- for(i = 0; i < 1000; i++){
- for (j = 0; j < 1000; j++){
- y++;
- z = x + y;
- x++;
- }
- }
- printf("Elapsed time = %.2f seconds\n", timer(FALSE));
- }
-
-
-
- float timer(int reset){
- static clock_t start;
- float elapsed;
-
- elapsed = (float)(clock() - start) / CLOCKS_PER_SEC;
- if(reset){
- start = clock();
- }
- return(elapsed);
- }
- Agent439@aol.com
- Fan of Doom, Doom2----Let the obsession begin....Again! (and again, and
- again!)
- Fan of Simpsons-----'nuff said
- Fan of Bulls-----Jordan's back! :-)
- Fan of AOL------3,000,000 members! (Only 93,000,000 households to go!)
- Fan of Van Halen
- Fan of Mancow's Morning Madhouse-ROCK 103.5FM (Chicago,Illinois)
-